package edu.tomee.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import edu.tomee.db.DatabaseConnection;
import edu.tomee.db.UserInfo;

/**
 * Servlet implementation class EditMyAccntServlet
 */
@WebServlet("/editmyaccnt")
public class EditMyAccntServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
	DatabaseConnection db = new DatabaseConnection();
    public EditMyAccntServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter out = response.getWriter();
		UserInfo UserDetails = new UserInfo();
		out.println();
		HttpSession session = request.getSession();
		UserDetails = (UserInfo) session.getAttribute("rslt");
		String eid = UserDetails.getEid();
		String pwd = UserDetails.getPwd();  //
		
//		String uid = request.getParameter("T1");
//		String fnm = request.getParameter("T2");
//		String lnm = request.getParameter("T3");
//		String phn = request.getParameter("T4");
//		String addr = request.getParameter("T6");
		String uid = request.getParameter("uid");
		String fnm = request.getParameter("fname");
		String lnm = request.getParameter("lname");
		String phn = request.getParameter("phn");
		String addr = request.getParameter("addrs");
		out.println("data received");
		System.out.println("phn "+phn);
		System.out.println("addrs "+addr);
		int updt_rslt = db.updateDetails(addr,fnm,lnm,phn,uid);
		System.out.println("updt_rslt "+updt_rslt);
		request.setAttribute("updt_rslt", updt_rslt);
		
		UserInfo editdtls = db.logincheck(eid, pwd);
		System.out.println("editdtls "+editdtls);
		session.setAttribute("rslt", editdtls);
		response.getWriter().println("Record Updated successfully");
		//request.getRequestDispatcher("updat_rprt.jsp").forward(request, response);
	}

}
